package com.example.rightmost.controller.admin;

import com.example.rightmost.entity.Result;
import com.example.rightmost.entity.Topic;
import com.example.rightmost.service.TopicService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:javayhch
 * @date:2024/8/20
 * @description:
 */

@RestController("adminTopicController")
@RequestMapping("/topic")
public class TopicController {

    @Autowired
    public TopicService topicService;

    //获取所有话题
    @RequestMapping("/getTopicList")
    public PageInfo getTopicList(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "5") int size,
                                 @RequestBody Topic topic
    ){
        PageHelper.startPage(page, size);
        List<Topic> list = topicService.getTopicList(topic);
        PageInfo<Topic> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //添加话题
    @RequestMapping("/addTopic")
    public Result addTopic(@RequestBody Topic topic){
        return topicService.addTopic(topic);
    }

    @RequestMapping("/updateTopic")
    public Result updateTopic(@RequestBody Topic topic){
        return topicService.updateTopic(topic);
    }

    //删除话题
    @RequestMapping("/deleteTopic")
    public Result deleteTopic(@RequestParam int id){
        return topicService.deleteTopic(id);
    }

    //启用，禁用话题
    @RequestMapping("/updateTopicStatus")
    public Result updateTopicStatus(@RequestParam int id){
        return topicService.updateStatus(id);
    }

}
